const Router = require('koa-router');
const {verifyAuth, verifyPermission, verifyPrivate} = require('../middleware/auth.middleware');
const {isExistClassify} = require('../middleware/exist.middleware');
const {
  create,
  remove,
  update,
  detail,
  list,
  classify,
  articles,
  createClassify,
  deleteClassify,
  updateClassify,
  articlePicInfo
} = require('../controller/article.controller');
const {support} = require('../controller/support.controller');

const articleRouter = new Router({prefix: "/article"});

// 创建一篇文章
articleRouter.post("/", verifyAuth, create);
// 删除一篇文章
articleRouter.delete("/:articleId", verifyAuth, verifyPermission, remove);
// 修改一篇文章
articleRouter.patch("/", verifyAuth, update);
// 获取一篇文章
articleRouter.get("/", detail);
// 获取文章列表
articleRouter.get("/list", verifyPrivate, list);
// 点赞文章
articleRouter.get("/:article/support", verifyAuth, support);
// 获取文章分类统计
articleRouter.get("/classify", classify);
// 按分类获取文章
articleRouter.get("/classify/:classifyId", articles);
// 创建文章分类
articleRouter.post("/classify", verifyAuth, isExistClassify, createClassify);
// 删除文章分类
articleRouter.delete("/classify/:classifyId", verifyAuth, deleteClassify);
// 修改文章分类
articleRouter.patch("/classify", verifyAuth, isExistClassify, updateClassify);
// 返回文章配图
articleRouter.get("/pic/:filename", articlePicInfo);

module.exports = articleRouter;
